﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Sector7.Restaurant.Biz;
using Sector7.Restaurant.Modules.BIZZ.Utility;
using Sector7.Restaurant.Modules.BIZZ.LocalService;
using Sector7.Framework.Enums;
using Sector7.Framework.Utility;
using Sector7.Framework.Core;

namespace Sector7.Restaurant.Modules.BIZZ.Windows
{
    /// <summary>
    /// PruchaseWindow.xaml 的交互逻辑
    /// </summary>
    public partial class PurchaseWindow : Window
    {
        /// <summary>
        /// 获取采购单
        /// </summary>
        public RS_PurchaseBill PurchaseBill
        {
            get { return purchaseDetailControl.PurchaseBill; }
        }

        public PurchaseWindow(List<RS_Metadata> metadatas, List<RS_Unit> units)
        {
            InitializeComponent();

            purchaseDetailControl.Metadatas = metadatas;
            purchaseDetailControl.Units = units;

            this.Owner = Senvironments.MainWindow;
        }

        private void LoadData()
        {
            List<RS_MetadataType> types = Aide.LocalClient.Invoke<List<RS_MetadataType>>(
                service => service.GetAllMetadataTypesForUsage((int)MetadataUsageType.Stock, true));
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            LoadData();
        }

        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            purchaseDetailControl.RemoveInvalidItem();

            string result = Aide.LocalClient.Invoke<string>(
                service => service.AddPurchaseBill(purchaseDetailControl.PurchaseBill));

            purchaseDetailControl.PurchaseBill.BillId = result;

            if (result != null)
                this.DialogResult = true;
            else
                this.DialogResult = false;
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}
